#include "SceneLoading.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "deprecated/CCDeprecated.h"
#include "ui/UIHelper.h"
#include "base/CCConsole.h"

USING_NS_CC;
using namespace ui;

float CSceneLoading::m_Percent = 0.00;

CSceneLoading::CSceneLoading(void)
{
}


CSceneLoading::~CSceneLoading(void)
{
}

bool CSceneLoading::init() {
	// 1. super init first
    if ( !CSceneBase::init() )
    {
        return false;
    }
	m_Percent = 0.00;
    
	m_Loading = CSLoader::createNode("Loading.csb");
	m_LoadingBar = (ui::LoadingBar*)ui::Helper::seekWidgetByTag((cocos2d::ui::Widget*)m_Loading, 662);
	addChild(m_Loading);

    return true;
}

/*
void CSceneLoading::onEnter() {
	cocos2d::Scene::onEnter();
}
void CSceneLoading::onExit() {
	cocos2d::Scene::onExit();
}

void CSceneLoading::update(float delta) {
	cocos2d::Scene::update(delta);
}
*/

void CSceneLoading::Loading(float p) {
	float tP = m_LoadingBar->getPercent();
	if (tP >= 100.00)
		return;
	p += (tP + m_Percent);
	m_LoadingBar->setPercent(p);
	if (p >= 100.00)
	{
		m_Director->getScheduler()->performFunctionInCocosThread(CC_CALLBACK_0(CSceneLoading::onLoading, this));
	}
}

void CSceneLoading::onLoading() {
	if (m_LoadingBar->getPercent() >= 100.00) {
		this->ReplaceScene(CSceneManager::SceneIndexHome);
		m_Percent = 0.00;
	}
}
